﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using weikebuluo.DAL;
using weikebuluo.Common;
using weikebuluo.Model;

namespace weikebuluo.web.admin.actives
{
    public partial class dzp : weikeweixin.web.admin.cs.adminbase
    {
        h_dzp_dal dzpdal = new h_dzp_dal();
        protected h_dzp_model dzpmodel = new h_dzp_model();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"])) {
                dzpmodel = dzpdal.GetModel(int.Parse(Request.QueryString["id"].ToString()));
            }
            switch (Request.Form["action"])
            {
                case "save"://提交信息
                    save();
                    break;
            }

            switch (Request.QueryString["action"])
            {
                case "del":
                    del();
                    break;

            }
        }

        //保存设置
        private void save()
        {
            if (!string.IsNullOrEmpty(Request.Form["id"]))
            {
                dzpmodel = dzpdal.GetModel(int.Parse(Request.Form["id"].ToString()));
            }
            dzpmodel.dzp_title = Request.Form["dzp_title"];
            dzpmodel.dzp_jx1 = Request.Form["dzp_jx1"];
            dzpmodel.dzp_jx2 = Request.Form["dzp_jx2"];
            dzpmodel.dzp_jx3 = Request.Form["dzp_jx3"];
            dzpmodel.dzp_content = Request.Form["dzp_content"];
            dzpmodel.dzp_num1 = int.Parse(Request.Form["dzp_num1"]);
            dzpmodel.dzp_num2 = int.Parse(Request.Form["dzp_num2"]);
            dzpmodel.dzp_num3 = int.Parse(Request.Form["dzp_num3"]);
            dzpmodel.dzp_gl1 = int.Parse(Request.Form["dzp_gl1"]);
            dzpmodel.dzp_gl2 = int.Parse(Request.Form["dzp_gl2"]);
            dzpmodel.dzp_hl3 = int.Parse(Request.Form["dzp_hl3"]);
            string[] NTime = Request.Form["time"].Split('-');
            dzpmodel.dzp_time1 = DateTime.Parse(NTime[0].Trim());
            dzpmodel.dzp_time2 = DateTime.Parse(NTime[1].Trim());
            dzpmodel.user_id = int.Parse(user_id);

            if (!string.IsNullOrEmpty(Request.Form["id"]))
            {
                dzpdal.Update(dzpmodel);
            }
            else {
                dzpdal.Add(dzpmodel);
            }
            Response.Write("{\"errno\":\"0\",\"tip\":\"设置成功！\",\"url\":\"dzplist.aspx\",\"error\":\"\"}");
            Response.End();
        }

        //删除
        private void del()
        {
            bool bl = dzpdal.Delete(int.Parse(Request.QueryString["dzp_id"].Trim()));
        }
    }
}